package com.kkb.hbase.mr.demo2UDInputFormat;

import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

/**
 * k1 类型不关心
 * v1 类型为byte[] -> BytesWritable
 * k2 文件路径/名字
 * v2 文件内容
 */
public class MyMapper extends Mapper<NullWritable, BytesWritable, Text,BytesWritable> {

    /**
     *
     * @param key
     * @param value 小文件的全部内容
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(NullWritable key, BytesWritable value, Context context) throws IOException, InterruptedException {
        //获取文件名字
        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        String name = inputSplit.getPath().getName();
        //把文件路径/名字作为key,内容作为value
        context.write(new Text(name),value);
    }
}
